package cn.butcher21.controller;

import cn.butcher21.dao.DaoWork;
import cn.butcher21.dao.DaoWorkImpl.DaoWorkImpl;
import cn.butcher21.pojo.Click;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

/**
 * butcher create in 2021/04/10/21:50
 */
@WebServlet("/getDetail")
public class LookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        DaoWork daoWork = new DaoWorkImpl();
        String id = request.getParameter("id");
        try {
            List<Click> list = daoWork.lookClick(id);

            Gson gson = new Gson();
            String s = gson.toJson(list);
            response.setContentType("application/json;charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.print(s);
            out.flush();
            out.close();
        } catch (SQLException e) {
            e.printStackTrace();
            response.setStatus(500);
        }
    }
}
